#!/bin/bash
# 检查 build-essential 包是否未安装，如果是，则安装它
if ! dpkg -s build-essential > /dev/null 2>&1; then
    apt-get update -y
    apt-get install -y build-essential
fi
#检查 cmake 是否已安装
if ! command -v cmake >/dev/null 2>&1; then
    echo "cmake 未安装正在尝试安装"
    apt-get update -y
    apt-get install -y cmake
fi
# 获取当前脚本的绝对路径
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd $(dirname $SCRIPT_PATH)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    exit 1
fi
#rm -rf /opt/external/project/ssh/libssh-0.11.2/src/ssh_build-stamp/ssh_build-configure*
#rm -rf /opt/external/project/mysql/client/mysql-9.4.0/src/mysql_client_build_mysql-9.4.0-stamp/mysql_client_build_mysql-9.4.0-download*
cd ..
CMAKEWORKDIR=$(pwd)
# 生成临时文件
#build_DIR="/tmp/$(date +"%Y-%m-%d-%H-%M-%S")"
build_DIR="/tmp/build/library-manager/debug"
#删除 临时文件
rm -rf $build_DIR
#build_DIR="/opt/net-drive/build"
# 生成构建目录-DBUILD_SHARED_LIBS=OFF \  # 禁用共享库
cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=debug \
-D CMAKE_INSTALL_PREFIX=/opt/app \
-D EXTERNA_USERS_SYSTEM_ROOT=/opt/system \
-D EXTERNAL_PROJECT_ROOT=/opt/module \
-D WITH_X264=ON \
-S $CMAKEWORKDIR -B $build_DIR
cmake --build $build_DIR -j$(nproc)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    rm -rf $build_DIR
    exit 1
fi
# 安装
cmake --install $build_DIR









